<div class="modal small fade" id="del-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<form id="deluser-form"  method="post"  role="form">
    {% csrf_token %}



    <div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">删除部门</h3>
        </div>

        <div class="modal-body">
            <p class="error-text"><i class="fa fa-warning modal-icon"></i>您确定要删除部门{{ obj_list.id }}<br>删除后无法恢复</p>
        </div>

        <div class="modal-footer">


           <input type="button" name='id' id='10'>

            <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
            <button id="test-post" class="btn btn-danger" data-dismiss="modal">Delete</button>
            <button id="login-button" type="submit" class="btn btn-primary">
                        删除
                    </button>
        </div>

      </div>
    </div>

</form>
    </div>

<script language="javascript" type="text/javascript">
    $('#deluser-form').submit(function(){
        $.ajax({
            type:"POST",
            url:"/deluser/10",
            data:{"user_id":$("#10").val()},
            beforeSend:function(xhr){
                xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken'));
            },
            success:function(data,textStatus){
                var errors = data["errors"];
                if(errors.length==0){
                    location.reload();
                }

            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                alert(XMLHttpRequest.responseText);
            }

        });
        return false;
    });

    $("#login-button").click(function(){
        $("#del-modal .alert").remove();
    });


    $('#register-form').submit(function(){
        $.ajax({
            type:"POST",
            url:"/usercontrol/register",
            data:{"username":$("#register-username").val(),"email":$("#register-email").val(),
                  "password1":$("#register-password-1").val(),"password2":$("#register-password-2").val(),},
            dataType:'json',
            beforeSend:function(xhr){
                xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken'));
            },
            success:function(data,textStatus){
                var errors = data["errors"];
                if(errors.length==0){
                    location.reload();
                }
                else{
                    //alert(errors);
                    var html = "<div class=\"alert alert-danger\">"
                    for (var key in errors){
                        html += errors[key]+"<br/>";
                    }
                    html += "</div>";
                    $("#register-modal .modal-header").after(html);
                }

            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                alert(XMLHttpRequest.responseText);
            }
        });
        return false;
    });

    $("#register-button").click(function(){
        $("#register-modal .alert").remove();
    });

    $("#logout").click(function(){
        $.ajax({
            type:"POST",
            url:"/usercontrol/logout",
            beforeSend:function(xhr){
                xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken'));
            },
            success:function(data,textStatus){
                location.replace("/");
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
                alert(XMLHttpRequest.responseText);
            }
        });
        return false;
    });
</script>
